//
//  ZGWShiLiBaoBaoSimularityPeopleTableViewCell.m
//  1gene
//
//  Created by 张国文 on 16/6/21.
//  Copyright © 2016年 1jiyin. All rights reserved.
//

#import "ZGWShiLiBaoBaoSimularityPeopleTableViewCell.h"


@implementation ZGWShiLiBaoBaoSimularityPeopleTableViewCell

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self addMySubview];
    }
    return self;
}

// 布局
- (void)addMySubview
{
    // 用户头像
    self.userImageV = [[UIImageView alloc] initWithFrame:CGRectMake(15 * kAdjustParamater, 20 * kAdjustParamater, 60 * kAdjustParamater, 60 * kAdjustParamater)];
    self.userImageV.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.1];
    self.userImageV.layer.cornerRadius = self.userImageV.width / 2;
    self.userImageV.layer.masksToBounds = YES;
    [self.contentView addSubview:_userImageV];
    
    // 名字
    self.userNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.userImageV.right + 7 * kAdjustParamater, self.userImageV.top + 7 * kAdjustParamater, 100 * kAdjustParamater, 15 * kAdjustParamater)];
  //  self.userNameLabel.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.1];
    self.userNameLabel.textColor = [UIColor blackColor];
    self.userNameLabel.textAlignment = NSTextAlignmentLeft;
    self.userNameLabel.font = [UIFont systemFontOfSize:k16Big];
    [self.contentView addSubview:_userNameLabel];
    
    // 性别图标
    self.userGenderImageV = [[UIImageView alloc] initWithFrame:CGRectMake(self.userNameLabel.right + 8 * kAdjustParamater, self.userNameLabel.top, 15 * kAdjustParamater, 15 * kAdjustParamater)];
    [self.contentView addSubview:_userGenderImageV];
    
    // 标签
    self.userTagLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.userNameLabel.left, self.userNameLabel.bottom + 15 * kAdjustParamater, 200 * kAdjustParamater, 15 * kAdjustParamater)];
  //  self.userTagLabel.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.1];
    self.userTagLabel.textColor = kCyanColor;
    self.userTagLabel.textAlignment = NSTextAlignmentLeft;
    self.userTagLabel.font = [UIFont systemFontOfSize:k14Big];
    [self.contentView addSubview:_userTagLabel];
    
    // 评分
    self.userPingFenLabel = [[UILabel alloc] initWithFrame:CGRectMake((375 - 40) * kAdjustParamater, 40 * kAdjustParamater, 40 * kAdjustParamater, 20 * kAdjustParamater)];
    self.userPingFenLabel.textColor = [UIColor blackColor];
    self.userPingFenLabel.textAlignment = NSTextAlignmentLeft;
    self.userPingFenLabel.font = [UIFont systemFontOfSize:k16Big];
    [self.contentView addSubview:_userPingFenLabel];
}

- (void)setZgwSimularityPeopleModel:(ZGWShiLiBaoGaoSimularityPeopleModel *)zgwSimularityPeopleModel
{
    // 用户头像
    [self.userImageV sd_setImageWithURL:[NSURL URLWithString:zgwSimularityPeopleModel.avatar_url] placeholderImage:[UIImage imageNamed:@""]];
    if ([zgwSimularityPeopleModel.isMine isEqualToString:@"YES"]) {
        // 用户姓名
        self.userNameLabel.text = zgwSimularityPeopleModel.nickName;
        self.userNameLabel.textColor = [UIColor redColor];
    } else if ([zgwSimularityPeopleModel.isMine isEqualToString:@"NO"]) {
        // 用户姓名
        self.userNameLabel.text = zgwSimularityPeopleModel.nickName;
    }
   
    // 自适应宽度
    CGRect newFrame = self.userNameLabel.frame;
    newFrame.size.width = [[NetStatusHandle shareHandle] adjustWidth:self.userNameLabel.text size:16 height:20];
    self.userNameLabel.frame = newFrame;
    // 性别图标改变位置
    self.userGenderImageV.frame = CGRectMake(self.userNameLabel.right + 8 * kAdjustParamater, self.userGenderImageV.frame.origin.y, self.userGenderImageV.width, self.userGenderImageV.height);
    NSString *genderString = zgwSimularityPeopleModel.sex;
    if ([genderString isEqualToString:@"0"]) {
        // 男
        self.userGenderImageV.image = [UIImage imageNamed:@"nan-shilibaogao"];
    } else if ([genderString isEqualToString:@"1"]) {
        // 女
        self.userGenderImageV.image = [UIImage imageNamed:@"nv-shilibaogao"];
    }
    // 标签
    NSMutableString *tagText = [NSMutableString stringWithFormat:@""];
    for (NSString *tagString in zgwSimularityPeopleModel.tagArray) {
        [tagText appendString:[NSString stringWithFormat:@"#%@", tagString]];
    }
    self.userTagLabel.text = tagText;
    // 评分
    NSString *pingFenString = [NSString stringWithFormat:@"%.1f", [zgwSimularityPeopleModel.health_score floatValue] * 10];
    self.userPingFenLabel.text = pingFenString;
    // 五角星
    float pingFenCount = [pingFenString floatValue];
    // 记录五角星的布局数组
    NSMutableArray *wuJiaoXingArray = [NSMutableArray array];
    if (pingFenCount > 0.0 && pingFenCount <= 1.0) {
        [wuJiaoXingArray addObject:@"2"];
        [wuJiaoXingArray addObject:@"3"];
        [wuJiaoXingArray addObject:@"3"];
        [wuJiaoXingArray addObject:@"3"];
        [wuJiaoXingArray addObject:@"3"];
    } else if (pingFenCount > 1.0 && pingFenCount <= 2.0) {
        [wuJiaoXingArray addObject:@"1"];
        [wuJiaoXingArray addObject:@"3"];
        [wuJiaoXingArray addObject:@"3"];
        [wuJiaoXingArray addObject:@"3"];
        [wuJiaoXingArray addObject:@"3"];
    } else if (pingFenCount > 2.0 && pingFenCount <= 3.0) {
        [wuJiaoXingArray addObject:@"1"];
        [wuJiaoXingArray addObject:@"2"];
        [wuJiaoXingArray addObject:@"3"];
        [wuJiaoXingArray addObject:@"3"];
        [wuJiaoXingArray addObject:@"3"];
    } else if (pingFenCount > 3.0 && pingFenCount <= 4.0) {
        [wuJiaoXingArray addObject:@"1"];
        [wuJiaoXingArray addObject:@"1"];
        [wuJiaoXingArray addObject:@"3"];
        [wuJiaoXingArray addObject:@"3"];
        [wuJiaoXingArray addObject:@"3"];
    } else if (pingFenCount > 4.0 && pingFenCount <= 5.0) {
        [wuJiaoXingArray addObject:@"1"];
        [wuJiaoXingArray addObject:@"1"];
        [wuJiaoXingArray addObject:@"2"];
        [wuJiaoXingArray addObject:@"3"];
        [wuJiaoXingArray addObject:@"3"];
    } else if (pingFenCount > 5.0 && pingFenCount <= 6.0) {
        [wuJiaoXingArray addObject:@"1"];
        [wuJiaoXingArray addObject:@"1"];
        [wuJiaoXingArray addObject:@"1"];
        [wuJiaoXingArray addObject:@"3"];
        [wuJiaoXingArray addObject:@"3"];
    } else if (pingFenCount > 6.0 && pingFenCount <= 7.0) {
        [wuJiaoXingArray addObject:@"1"];
        [wuJiaoXingArray addObject:@"1"];
        [wuJiaoXingArray addObject:@"1"];
        [wuJiaoXingArray addObject:@"2"];
        [wuJiaoXingArray addObject:@"3"];
    } else if (pingFenCount > 7.0 && pingFenCount <= 8.0) {
        [wuJiaoXingArray addObject:@"1"];
        [wuJiaoXingArray addObject:@"1"];
        [wuJiaoXingArray addObject:@"1"];
        [wuJiaoXingArray addObject:@"1"];
        [wuJiaoXingArray addObject:@"3"];
    } else if (pingFenCount > 8.0 && pingFenCount <= 9.0) {
        [wuJiaoXingArray addObject:@"1"];
        [wuJiaoXingArray addObject:@"1"];
        [wuJiaoXingArray addObject:@"1"];
        [wuJiaoXingArray addObject:@"1"];
        [wuJiaoXingArray addObject:@"2"];
    } else if (pingFenCount > 9.0 && pingFenCount <= 10.0) {
        [wuJiaoXingArray addObject:@"1"];
        [wuJiaoXingArray addObject:@"1"];
        [wuJiaoXingArray addObject:@"1"];
        [wuJiaoXingArray addObject:@"1"];
        [wuJiaoXingArray addObject:@"1"];
    }

    // 进行五角星的动态布局
    for (int i = 0; i < wuJiaoXingArray.count; i++) {
        NSString *count = wuJiaoXingArray[i];
        UIImageView *wuJiaoXingImageV = [[UIImageView alloc] initWithFrame:CGRectMake(272 + (10 + 2) * i * kAdjustParamater, 45 * kAdjustParamater, 10 * kAdjustParamater, 10 * kAdjustParamater)];
        if ([count isEqualToString:@"1"]) {
            // 彩色
            wuJiaoXingImageV.image = [UIImage imageNamed:@"hangseWuJiaoXing-shilibaogao"];
        } else if ([count isEqualToString:@"2"]) {
            // 半彩色
            wuJiaoXingImageV.image = [UIImage imageNamed:@"bancaisewujiaoxing-shilibaogao"];
        } else if ([count isEqualToString:@"3"]) {
            // 灰色
            wuJiaoXingImageV.image = [UIImage imageNamed:@"huisewujiaoxing-shilibaogao"];
        }
        [self.contentView addSubview:wuJiaoXingImageV];
    }

    
    
    
}

@end
